package com.yzpass.api;

import java.nio.file.Paths;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;


public class CodeGenerator {
    public static void main(String[] args) {
        String password = System.getenv().get("spring.datasource.password");
        System.out.println(password);
        String outputDir = Paths.get(System.getProperty("user.dir")) + "/target/generated-src";
        System.out.println(outputDir);

        FastAutoGenerator.create("jdbc:postgresql://localhost:5432/yzpass", "postgres", password)
                .globalConfig(builder -> builder
                        .author("junfeng")
                        .outputDir(outputDir)
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.yzpass.ms.user")
                        .entity("entity")
                        .mapper("mapper")
                )
                .strategyConfig(builder -> builder
                        .addTablePrefix("yu_")
                        .entityBuilder().enableLombok().enableFileOverride()
                        .serviceBuilder().disable()
                        .controllerBuilder().disable()
                        .mapperBuilder().enableFileOverride().disableMapperXml()
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
